/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import Entity.PhieuThuTien;
import Util.DatabaseHandle;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author copang
 */
public class PhieuThuTienImpl implements PhieuThuTienDAO{

    public boolean add(PhieuThuTien data) {
        String sql = "{ call sp_PHIEUTHUTIEN_add(?,?,?,?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);

        try {
            db.setOutParameter(1, java.sql.Types.INTEGER);
            db.setParameter(2, data.getMaKhachHang());
            db.setParameter(3, data.getNgayThuTien());
            db.setParameter(4, data.getSoTienThu());

            db.executeStorePro();
            data.setMaPhieuThuTien(db.getIntOutValue(1));
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(PhieuThuTienImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean delete(int MaPhieuThuTien) {
         String sql = "{ call sp_BAOCAOCONGNO_delete(?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);

        try {

            db.setParameter(1, MaPhieuThuTien);
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(PhieuThuTienImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

}
